// 封装频道相关的数据请求

import {useEffect, useState} from "react";
import {ChannelAPI} from "@/apis";

function useChannels() {
    // 1. 封装获取频道列表数据所有逻辑
    const [channelList, setChannelList] = useState([])
    useEffect(() => {
        //  封装函数调用请求接口
        const getChannelList = async () => {
            const res = await ChannelAPI()
            setChannelList(res.data.channels)
        }
        //  调用函数
        getChannelList()
    }, []);

    //2. return出频道相关的数据
    return {
        channelList
    }
}

export default useChannels